#include "comm.hpp"
#include "unistd.h"


int main()
{
    key_t k = getkey();
    printf("key : 0x%x\n",k);

    int shmid = creatShm(k);
    printf("shmid : 0x%x\n",shmid);
    sleep(5);

    //挂接
    char* start = (char*)attachShm(shmid);
    printf("attach shm success! address start: %p\n", start);
    sleep(5);

    //使用shm
    int cnt = 50;
    while(cnt--)
    {
        //这里可以用一个buffer缓冲区来判定是否需要退出循环
        printf("%s[pid:%d][剩余消息:%d][time:%d]\n", start, getpid(), cnt, std::time(0));
        sleep(1);
    }

    //去关联
    detachShm(start);
    printf("deattach shm success! address start: %p\n", start);
    sleep(10);

    //删除shm
    delshm(shmid);
    printf("delete shm success! \n");

    return 0;
}